#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/7/23 6:42 上午
# @Author : lihc
# @File : concact_page.py
from selenium.webdriver.common.by import By

from seleniumdemo.po.add_member_page import AddMemberPage
from seleniumdemo.po.base_page import BasePage


class ContactPage(BasePage):
    _contact_add_member = (By.CSS_SELECTOR, '.member_colRight_cnt_operation:nth-child(1)')
    _member_username_td = (By.CSS_SELECTOR, ".member_colRight_memberTable_td:nth-child(2)")

    # 页面地址
    def __init__(self, base_driver=None):
        self.read_config_file()
        self._home_page_url = self.conn.get('URL', 'contact_url')

        BasePage.__init__(self)

    #  点击添加成员按钮
    def click_add_member(self):
        '''
        跳转到添加成员页面
        :return:
        '''
        # 点击添加成员按钮
        self.find(*self._contact_add_member).click()
        
        # 跳转到添加成员页面
        return AddMemberPage(self.driver)

    # 保存信息后返回成员列表页面
    def get_member_list(self):
        '''
        PO原则：不要在方法内加断言
        获取通讯录列表
        :return:
        '''

        # 获取列表中用户名
        ele = self.finds(*self._member_username_td)

        # 列表用户名
        name_list = [i.text for i in ele]
        
        return name_list

    # 回到首页
    def click_home_page(self):
        from seleniumdemo.po.home_page import HomePage

        # 点击首页Tab选项卡
        self.driver.find_element(By.ID, 'menu_index').click()

        # 跳转到首页
        return HomePage()
    